set more off
clear all

import excel "income_us.xlsx", sheet("Sheet1") firstrow clear


rename Personalincome i_income_total
rename Compensationofemployees i_compensation_of_employees
rename Wagesandsalaries i_wages
rename Personalincomereceiptson i_interest
rename Personalcurrenttransferre i_transfers

save temp, replace

import delimited "consumption_by_function.csv", encoding(ISO-8859-1) clear


merge 1:1 year using temp
erase temp.dta
drop _merge


rename personalconsumptionexpenditures c_total
rename recreation c_rec_total
rename videoandaudioequipmentcomputersa c_rec_video_audio_comp
	rename videoandaudioequipment c_rec_video_audio
	rename informationprocessingequipment c_rec_info_proc_equipment
	rename servicesrelatedtovideoandaudiogo c_rec_services_video_audio
rename sportsandrecreationalgoodsandrel c_rec_sport
rename membershipclubssportscenterspark c_rec_admission
rename magazinesnewspapersbooksandstati c_rec_books
rename gambling c_rec_gambling
rename petspetproductsandrelatedservice c_rec_pet
rename photographicgoodsandservices c_rec_photo
rename packagetours14 c_rec_tours

rename communication c_communication
rename transportation c_transportation
rename furnishingshouseholdequipmentand c_furnishing
rename housingutilitiesandfuels c_housing
rename health c_health
rename education c_education

order year c_* i_*
keep year c_* i_*

replace c_rec_video_audio="" if c_rec_video_audio=="---"
replace c_rec_info_proc_equipment="" if c_rec_info_proc_equipment=="---"
replace c_rec_services_video_audio="" if c_rec_services_video_audio=="---"

destring c_*, replace



gen frac_rec_total=c_rec_total/c_total
gen frac_rec_no_infoproc=(c_rec_total-c_rec_info_proc_equipment-c_rec_services_video_audio*c_rec_info_proc_equipment/(c_rec_video_audio+c_rec_info_proc_equipment))/c_total
gen frac_rec_no_infoproc_serv=(c_rec_total-c_rec_info_proc_equipment-c_rec_services_video_audio)/c_total
gen frac_communication=c_communication/c_total
gen frac_furnishing=c_furnishing/c_total
gen frac_transport=c_transportation/c_total
gen frac_housing=c_housing/c_total
gen frac_health=c_health/c_total
gen frac_rec_kop=(c_rec_total+0.3*c_transportation)/c_total






gen frac_within_rec_video_audio_comp=c_rec_video_audio_comp/c_rec_total
gen frac_within_rec_sport=c_rec_sport/c_rec_total
gen frac_within_rec_admission=c_rec_admission/c_rec_total
gen frac_within_rec_books=c_rec_books/c_rec_total
gen frac_within_rec_gamling=c_rec_gambling/c_rec_total
gen frac_within_rec_pet=c_rec_pet/c_rec_total
gen frac_within_rec_photo=c_rec_photo/c_rec_total
gen frac_within_rec_tours=c_rec_tours/c_rec_total
gen frac_within_rec_equiptment=c_rec_info_proc_equipment/c_rec_total



replace frac_rec_no_infoproc=frac_rec_total if frac_rec_no_infoproc==. /*in early observations those are virtually the same*/



gen frac_cons_income=c_total/i_income_total
gen frac_cons_compensation=c_total/i_compensation_of_employees
gen frac_within_inc_interest=i_interest/i_income_total
gen frac_within_inc_comp=i_compensation_of_employees/i_income_total
gen frac_within_inc_transfer=i_transfers/i_income_total



merge 1:1 year using "../CEX_data/rec_cex"

gen frac_rec_cex=cons_rec/totexp

twoway (connected frac_rec_no_infoproc frac_rec_total frac_rec_cex year, /*
*/lpattern(solid dash solid) /*
*/msymbol(p p x) msize(small small large)), /*
*/leg(label (1 "NIPA") label(2 "NIPA, with computers") label(3 "CE Surveys") position(11) ring(0) cols(1)) /*
*/xlabel(1930[10]2020) ylabel(0.0[0.05]0.2) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax gmin) ylabel(,grid nogextend gmin gmax) ysize(4)
graph export "../figures/frac_recreation_cons_USA.png", as(png) replace
graph export "../figures/frac_recreation_cons_USA.eps", as(eps) replace

*black and white
twoway (connected frac_rec_no_infoproc frac_rec_total frac_rec_cex year, /*
*/lpattern(solid dash solid) /*
*/msymbol(p p x) msize(small small large)), /*
*/leg(label (1 "NIPA") label(2 "NIPA, with computers") label(3 "CE Surveys") position(11) ring(0) cols(1)) /*
*/xlabel(1930[10]2020) ylabel(0.0[0.05]0.2) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax gmin) ylabel(,grid nogextend gmin gmax) ysize(4) scheme(s1mono)
graph export "../figures/frac_recreation_cons_USA_bw.png", as(png) replace
graph export "../figures/frac_recreation_cons_USA_bw.eps", as(eps) replace
 
